package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 订单
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 用户下单
     * @param orders
     * @return
     */

    @PostMapping("/submit")
    public R<String> submit(@RequestBody Orders orders){
    orderService.submit(orders);
    return R.success("下单成功");
    }

    @GetMapping("/page")
    public R pageBack(int page, int pageSize) {
        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
        Page<Orders> pageInfo = new Page(page, pageSize);
        orderService.page(pageInfo, queryWrapper);
        return R.success(pageInfo);
    }

    @GetMapping("/userPage")
    public R pageFront(int page, int pageSize) {
        LambdaQueryWrapper<Orders> queryWrapper = new LambdaQueryWrapper<>();
        Page<Orders> pageInfo = new Page(page, pageSize);
        orderService.page(pageInfo, queryWrapper);
        //List records = pageInfo.getRecords();
        //Map<String, List> map = new HashMap<>();
        //
        //map.put("records", records);
        return R.success(pageInfo);
    }



}
